define(function(require, exports, module){
	require("resource/js/easyui/themes/icon.css");
	require("resource/js/easyui/easyloader.js");
	require("resource/js/component/rules.js");
	require("resource/js/component/backSpace.js");
	var CONST = require("resource/js/config/const.js");
	var Check = require("resource/js/component/check.js");
	var AJAX = require("resource/js/component/ajax.js");
	var EUtil = require("resource/js/component/easyutil.js");
	var ECombobox = require("resource/js/component/easycombobox.js");
	
	//var Obj = window.loadI18n('base/user1');
	
	var Obj = {};
	
	
	ECombobox.create({
		url:BASEPATH+"/base/authoriza/basecode/getType.htm",
		param:{checkeds:"status,usertype,sex,systype"}
	})
	var userModel = undefined;
	
	var dgutil = undefined;
	var config = function(){
		
		return {
				column:[[
				         {field:'userId',title:''+Obj.get("base.user.js.userid")+''/*用户ID*/,width:100,align:'center',height:50,hidden:true},
				         {field:'userName',title:''+Obj.get("base.user.main.name")+''/*姓名*/,width:100,align:'center',height:50},
				         {field:'userCode',title:''+Obj.get("base.user.main.account.number")+''/*姓名*/,width:100,align:'center',height:50},//
				         {field:'deptName',title:''+'所属组织架构'+''/*所属(单位)部门*/,width:100,align:'center',height:50},
				         {field:'mobile',title:''+Obj.get("base.user.main.cellphone")+''/*手机号码*/,width:90,align:'center',height:50},
				         {field:'telphone',title:''+Obj.get("base.user.main.telephone_1")+''/*电话号码*/,width:90,align:'center',height:50,hidden:true},
				         {field:'cardNo',title:''+Obj.get("base.user.add.IDNumber")+''/*身份证号*/,width:100,align:'center',height:50,sortable:true,hidden:true},
				         {field:'userTypeName',title:''+Obj.get("base.user.main.type")+''/*用户类型*/,width:100,align:'center',height:50},
				         {field:'userImg',title:''+Obj.get("base.user.add.pic")+''/*用户头像*/,width:50,align:'center',hidden:true,
				        	 formatter:function(value,row,index){
					        		if(value){
										if (value.indexOf("icon")!=-1){
											return '<span class="l-btn-left l-btn-icon-left" style="margin-top: 2px;"><span class="l-btn-text"></span><span class="l-btn-icon '+value+'">&nbsp;</span></span>';
										}else{
											return "<img class='click' style='width:30px;height:30px;' onclick='imgByUrl(\""+BASEPATH+value+"\");' src='"+BASEPATH+value+"'/>";
										}
					        		}
					        	}},
				         {field:'email',title:'Email',width:90,align:'center',height:50},
				         {field:'operDate',title:''+Obj.get("base.user.js.createtime")+''/*创建时间*/,width:100,align:'center',height:50,sortable:true,hidden:true},
				         {field:'statusName',title:''+Obj.get("base.user.main.status")+''/*可用状态*/,width:60,align:'center',height:50}
				         ]]
		};
	}
	var datagridconfig = undefined;
	function initCheck(row){
		var chechUserCode = function(value){
			$("#userCode").textbox("options").validate=undefined;
			AJAX.init().success(function(code,msg,data){
				if(data){
					//$.messager.show({ title:CONST.MESSAGE.MSGTITLE, msg:CONST.MESSAGE.OKUSERCODE, timeout:3000, showType:'slide' });
					$("#userCode").textbox("options").validate=true;
				}else{
					$.messager.show({ title:CONST.MESSAGE.MSGTITLE, msg:CONST.MESSAGE.ERRUSERCODE, timeout:3000, showType:'slide' });
				}
			}).error(function(code,msg,data){
				$.messager.show({ title:CONST.MESSAGE.MSGTITLE, msg:msg, timeout:3000, showType:'slide' });
			}).sync().post(BASEPATH+"/base/authoriza/check/getUsercode.htm",{userCode:value});
		}
		var chechCardNo = function(value){
			$("#cardNo").textbox("options").validate=undefined;
			AJAX.init().success(function(code,msg,data){
				if(data){
					$.messager.show({ title:CONST.MESSAGE.MSGTITLE, msg:CONST.MESSAGE.OKCARDNO, timeout:3000, showType:'slide' });
					$("#cardNo").textbox("options").validate=true;
				}else{
					$.messager.show({ title:CONST.MESSAGE.MSGTITLE, msg:CONST.MESSAGE.ERRCARDNO, timeout:3000, showType:'slide' });
				}
			}).error(function(code,msg,data){
				alert(msg);
			}).sync().post(BASEPATH+"/base/authoriza/check/getUsercode.htm",{cardNo:value});
		}
		var userCodevalue,cardNovalue;
		if(row){
			userCodevalue= row.userCode;
			cardNovalue = row.cardNo;
		}
		$("#deptIdIpt").textbox({
			required:true,
			buttonText:"请选择",
			edit:true,
			value:"",
			onClickButton:function(value){
				$("#updtreeselecter").dialog("open");
			}
		});
		$("#userCode").textbox({
			required:true,
			validType:'code',
			buttonText:CONST.MESSAGE.CHECKUSERCODE,
			edit:true,
			value:userCodevalue,
			onClickButton:function(value){
				value = value||$(this).textbox('getValue');
				if(!$("#userCode").textbox("isValid")){
					return;
				}
				if(row&&row.userCode==value){
					return;
				}else{
					chechUserCode(value);
				}
			}
		});
		
		$("#cardNo").textbox({
			edit:true,
			buttonText:CONST.MESSAGE.CHECKCARDNO,
			value:cardNovalue,
			onClickButton:function(value){
				value = value||$(this).textbox('getValue');
				if(!$("#cardNo").textbox("isValid")){
					return;
				}
				if(Check.check('',"idcard",value)){
					if(row&&row.cardNo==value){
						return;
					}else{
						chechCardNo(value);
					}
				}else{
					$.messager.show({ title:CONST.MESSAGE.MSGTITLE, msg:CONST.MESSAGE.NOVALIDCARDNO, timeout:3000, showType:'slide' });
				}
			}
		});
	}
	var initUserImg = function(arg){
		using("upload",function(){
			$("#userImg").upload({
				buttonText:''+ Obj.get("base.user.js.selectDoc") +''/*选择文件*/,
			    iconCls:'icon-man', 
			    iconAlign:'left',
			    title:''+ Obj.get("base.user.js.updAva") +''/*上传头像*/,
	    		param:{exts:"png,bmp,jpg"},
				onClickButton:function(){
					$("#userImg").upload("show");
				}
			})
		})
	}
	//初始化用户类型下拉框数据
	var initUserType = function(id){
		var userType = userModel.userType;
		//初始化查询用户类型规则
		ECombobox.init({ ele:"#"+id, grouptype:"usertype",
			dataFilter:function(data){
				var res = [];
				$.each(data,function(i,item){
					if(parseInt(item.baseCode)<userType||parseInt(item.baseCode)==CONST.USERTYPE.NOMALUSER){
						res.push(item);
					}
				});
				return res;
			}
		});
	}
	//增加按钮保存事件
	var addDialogInit = function(url){
		$("#adduserdlg").dialog({
			iconCls: 'icon-save',
			title:''+ Obj.get("base.user.js.userAdd") +'',
			href:url,
			onLoad:function(){
				$("#deptId").ztreebox("dept");
				ECombobox.init({ ele:"#sex", grouptype:"sex" });
				initUserType("userType");
				initCheck();
				initUserImg();
			},
			buttons: [{
				text:''+ Obj.get("base.user.js.save") +'',
				iconCls:'icon-ok',
				accessKey:{akey:18,mkey:83},
				handler:function(){
					using(["form"],function(){
						if(!$("#addform").form("validate")){
							return ;
						}
						$("#userCode").textbox("options").onClickButton($("#userCode").textbox("getText"));
						if($("#userCode").textbox("options").validate!=true){
							return ;
						}
						if($("#cardNo").textbox("options").required){
							$("#cardNo").textbox("options").onClickButton($("#cardNo").textbox("getText"));
							if($("#cardNo").textbox("options").validate!=true){
								return ;
							}
						}
						var MD5 = require("resource/js/component/md5.js");
						//$("#password").textbox("setValue",MD5.md5($("#password").textbox("getText")).toUpperCase());
						//以requestBody方式提交ajax 保证用户部门信息完整
						var obj = $("#addform").serializeJson();
						obj.depts = obj['depts.deptId'].split(",");
						$.each(obj.depts,function(i,item){
							obj.depts[i] = {deptId:item};
						});
						obj.password = MD5.md5($("#password").textbox("getText")).toUpperCase();
						delete obj['depts.deptId'];
						
						AJAX.init().success(function(code,msg,data){
							$.messager.show({
								title:''+ Obj.get("base.user.js.sysHint") +''/*系统提示*/,
								msg:msg,
								timeout:2000,
								showType:'slide'
							});
							dgutil.pager();
							$("#adduserdlg").dialog("close");
	    	    		}).error(function(code,msg,data){
	    	    			$.messager.alert(''+ Obj.get("base.user.js.sysHint") +'', msg, "error");
	    	    		}).contentType('application/json').post(BASEPATH+'/base/authoriza/user/save.htm',JSON.stringify(obj));

					});
				}
			},{
				text:''+ Obj.get("base.user.js.cancel") +'',
				addClass:'l-btn-red',iconCls:'icon-not',
				accessKey:{akey:18,mkey:67},
				handler:function(){
					$('#adduserdlg').dialog('close');
				}
			}]
		});
		$("#adduserdlg").dialog("open");
	}
	function restTreeUpd(deptIds){
		var checks =[];
		using("ztree",function(){
			var T = require("resource/js/component/treeutil.js");
			var reg = null;
			
			//异步构建ztree
			var t = new T.ajaxTree({
				eid:"updtreeselecter",
				url:BASEPATH+"/base/authoriza/dept/getTreeall.htm",
				check:"checkbox",
				title:"",
				search:false,
				autoclose:false,
				checks:checks,
				args:"",
				save:function(data){
					showDeptIdNameText(data);
					$("#updtreeselecter").dialog("close");
				}  
				
			}).load(function(tree){
				tree.setting.check.chkboxType={ "Y": "", "N": "" };
				
				/*bug 10998 如果列表没有手机注册默认部门 则添加一个*/
				if(tree.getNodeByParam("id","17040614545700000111")==null){
					var nd = [{"id":"17040614545700000111", "pId":0, "name":"手机端注册账号默认部门"}];
					tree.addNodes(null,nd);
				}
				tree.checkAllNodes(false);
				var deptId = deptIds.split(",");
				
				for(t=0; t<deptId.length;t++){
					var snode =tree.getNodeByParam("id",deptId[t]);
					if(snode){
						tree.checkNode(snode,true,false);
					}
				}
				
				// 
				var selNode = tree.getCheckedNodes();
				showDeptIdNameText(selNode);
			});
		});
	}
	function showDeptIdNameText(data){
		var showNameText ="";
		var showIdText="";
		for(t=0;t<data.length;t++){
			
			showNameText += data[t].name;
			showIdText +=data[t].id;
			if(t < data.length - 1){
				showNameText = showNameText + ",";
				showIdText +=data[t].id + ",";
			}
			
		}
		$("#deptIdIpt").textbox("setValue",showNameText);
		$("#deptId").val(showIdText);
	}
	//更新按钮点击事件
	var updDialogInit = function(baseUrl,row){
		var editrow = row;
		using(["form"],function(){
			$("#adduserdlg").dialog({
				iconCls: 'icon-save',
				title:''+ Obj.get("base.user.js.userModify") +'',
				href:baseUrl,
				onLoad:function(){
					//查询的row缺少用户部门信息 此查询就是获取完整的用户信息
					AJAX.init().sync().success(function(code,msg,data){
						$('#updform').form('load',data[0]);
						var deptIds="";
						$.each(data[0].depts,function(i,item){
							deptIds+=item.deptId+",";
						});
						/*$("#deptId").val(deptIds);
						$("#deptId").ztreebox("dept");*/
						restTreeUpd(deptIds);
						
					}).post(BASEPATH+'/base/authoriza/user/queryUser.htm',{userId:row.userId});

					ECombobox.init({ ele:"#status", grouptype:"status",value:row.status});
					ECombobox.init({ ele:"#sex", grouptype:"sex",value:row.sex});
					initUserType("userType");
					initCheck(row);
					initUserImg(row.userImg);
				},
				buttons: [{
					text:''+ Obj.get("base.user.js.save") +'',
					iconCls:'icon-ok',
					accessKey:{akey:18,mkey:83},
					handler:function(){
						using(["form"],function(){
							if(!$("#updform").form("validate")){
								return;
							}
							var usercode = $("#userCode").textbox("getValue");
							var cardno = $("#cardNo").textbox("getValue");
							if(usercode!=row.userCode){
								if($("#userCode").textbox("options").validate!=true){
									$("#userCode").textbox("options").onClickButton(usercode);
									if($("#userCode").textbox("options").validate!=true){
										return ;
									}
								}
							}
							if(cardno!=""&&cardno!=row.cardNo){
								if($("#cardNo").textbox("options").validate!=true){
									$("#cardNo").textbox("options").onClickButton($("#cardNo").textbox("getText"));
									if($("#cardNo").textbox("options").validate!=true){
										return ;
									}
								}
							}
							//修改方式同增加
							var obj = $("#updform").serializeJson();
							obj.depts = obj['depts.deptId'].split(",");
							$.each(obj.depts,function(i,item){
								obj.depts[i] = {deptId:item};
							});
							delete obj['depts.deptId'];
							
							AJAX.init().success(function(code,msg,data){
								$.messager.show({
									title:''+ Obj.get("base.user.js.sysHint") +'',
									msg:msg,
									timeout:2000,
									showType:'slide'
								});
								dgutil.pager();
								$("#adduserdlg").dialog("close");
		    	    		}).error(function(code,msg,data){
		    	    			$.messager.alert(''+ Obj.get("base.user.js.sysHint") +'', msg, "error");
		    	    		}).contentType('application/json').post(BASEPATH+'/base/authoriza/user/update.htm',JSON.stringify(obj));
						});
					}
				}/*,{
					text:'重置',
					accessKey:{akey:18,mkey:82},
					handler:function(){
						$('#updform').form('load',row);
						$("#userCode").textbox("setValue",row.userCode);
					}
				}*/,{
					text:''+ Obj.get("base.user.js.cancel") +'',
					addClass:'l-btn-red',iconCls:'icon-not',
					accessKey:{akey:18,mkey:67},
					handler:function(){
						$('#adduserdlg').dialog('close');
					}
				}]
			});
			$("#adduserdlg").dialog("open");
		});
	}
	//删除按钮事件
	var delInit = function(url,rows){
		var checks = "";
		for(var key in rows){
			if(key==rows.length-1){
				checks += rows[key].userId;
			}else{
				checks += rows[key].userId+",";
			}
		}
		EUtil.ajaxHandler(url,{checkeds:checks},function(){
			dgutil.delRow(rows);
		});
	}
	//导出按钮事件
	var exportDialogInit = function(){
		alert(''+ Obj.get("base.user.js.exportData") +'');
	}
	//导入按钮事件
	var importDialogInit = function(baseUrl){
		using("upload",function(){
			var dlg = $("<input type='hidden'>").appendTo($("body"));
			dlg.upload({
	    		title:''+ Obj.get("base.user.js.userImport") +'',
	    		width:400,
	    		height:350,
	    		buttons:[],
	    		param:{formData:{oper:"import"},exts:"xlsx,xls"},
	    		onSuccessAfter:function(files){
	    			AJAX.init().success(function(code,msg,data){
						dgutil.pager();
						if(msg&&msg!=""){
							$.messager.show({ title:''+ Obj.get("base.user.js.sysHint") +'', msg:msg, timeout:2000, showType:'slide' });
						}
						$("#uploaddlg").dialog("close");
					}).error(function(code,msg,data){
						$.messager.alert(''+ Obj.get("base.user.js.sysHint") +'',msg);
					}).post(baseUrl,{path:files[0].file});
	    		}
	    	});
			dlg.upload("show");
			dlg.upload("dialog").dialog("addButton",{
				text:''+ Obj.get("base.user.js.temp") +'',
				handler:function(){
					location.href = BASEPATH+"/base/user/user.xls";
				},
				index:1
			});
		});
	}
	
	//角色分配按钮事件
	var roleDialogInit = function(baseUrl,rows){
		if(rows.length==1){
			var userId = rows[0].userId;
			var url = BASEPATH+"/base/authoriza/role/getRoleByUser.htm";
			var ajax = AJAX.init();
			var intiRoleTree = function(code,msg,data){
				var checks = [];
				var regexp = "";
				if(data!=undefined&&data.length>0){
					for(var k=0;k<data.length;k++){
						checks[k] = data[k].roleId;
						if(data[k].regexp!=undefined&&data[k].regexp!=''){
							regexp = data[k].regexp;
						}
					}
				}
				initRoleTree(baseUrl,checks,userId);
			}
			ajax.success(intiRoleTree).error(intiRoleTree).post(url,{userId:userId});
		}else{
			var userIds='';
			for(var i=0;i<rows.length;i++){
				if(i==rows.length-1){
					userIds += rows[i].userId ;
				}else{
					userIds += rows[i].userId + ",";
				}
				
			}
			initRoleTree(baseUrl,undefined,null,userIds);
		}
		
	}
	function initRoleTree(baseUrl,checks,userId,userIds){
		$("#treeselecter").dialog("open");
		using("ztree",function(){
			var T = require("resource/js/component/treeutil.js");
			var tree = new T.ajaxTree({
				eid:"treeselecter",
				url:BASEPATH+"/base/authoriza/role/getTreeall.htm",
				check:"checkbox",
				title:''+ Obj.get("base.user.js.roleSelection") +'',
				checks:checks,
				save:function(data){
					var checks = '';
					for(var k=data.length-1;k>=0;k--){
						if(k==0) checks+=data[k].id;
						else checks+=data[k].id+",";
					}
					//var url = BASEPATH+"/base/authoriza/userrole/save.htm";
					AJAX.init().success(function(code,msg,data){
						if(data){
							$.messager.show({ title:''+ Obj.get("base.user.js.sysHint") +'', msg:''+ Obj.get("base.user.js.saveSuc") +'', timeout:5000, showType:'slide' });
						}
					}).error(function(code,msg,data){
						$.messager.show({ title:''+ Obj.get("base.user.js.sysHint") +'', msg:''+ Obj.get("base.user.js.saveFail") +'', timeout:5000, showType:'slide' });
					}).post(baseUrl,{userId:userId,checkeds:checks,users:userIds});
				}
			});
			tree.setting.check.chkboxType={ "Y": "", "N": "" };

			tree.setting.callback.beforeCheck=function(treeId, treeNode) {
				if(treeNode.checked)
					return true;
				else {
					var treeobj = this.getZTreeObj(treeId);
					treeobj.setting.check.chkboxType={ "Y": "ps", "N": "ps" }
					treeobj.checkNode(treeNode,false,true,false);
					treeobj.setting.check.chkboxType={ "Y": "", "N": "" }
					return true;
				}
			}
			tree.load();
		});
	}
	function initpage(){
		dgutil = new EUtil.ajaxDataGrid(datagridconfig);
		ECombobox.init({ ele:"#searchStatus", grouptype:"status" });
		$("#searchUserDept").ztreebox("dept");
		$("#searchUserRole").ztreebox("role");
	}
		
	function resetpswd(url,row){
		AJAX.init().success(function(code,msg,data){
			if(code==0){
				$.messager.show({ title:''+ Obj.get("base.user.js.sysHint") +'', msg:msg, timeout:5000, showType:'slide' });
			}
		}).post(url,{userId:row.userId,userCode:row.userCode});
	}
	
	var addDeptToUser = function(baseUrl){
		$("#adduserdlg").dialog({
			iconCls: 'icon-save',
			title:''+ Obj.get("base.user.js.disDept") +'',
			href:baseUrl,
			onLoad:function(){
				$("#userMobole").textbox({
					validType:"mobile",
					prompt:''+ Obj.get("base.user.js.enterPhone") +'',
					required:true
				});
				$("<img title='"+ Obj.get("base.user.js.changePic") + "'>").attr("src", BASEPATH+'/base/authoriza/user/imgcode.htm'+"?_"+new Date().getTime()).on("click",function(){
					$(this).attr("src",BASEPATH+'/base/authoriza/user/imgcode.htm'+"?_"+new Date().getTime());
				}).insertAfter(
				$("#msgcode").textbox({
					buttonText:"&nbsp;",
					editable:true,
					validType:"length[4]",
					edit:true,
					prompt:''+ Obj.get("base.user.js.enterVerCode") +'',
					required:true
				}).textbox("textbox").prev()).css({"background":"transparent",width:"100px","right":"0px"}).attr("class",$("#msgcode").textbox("textbox").prev().prev().remove().attr("class"));
				$('#telephoneCode').textbox({
					prompt:''+ Obj.get("base.user.js.enterVerCode_1") +'',
					required:true,
				})
				using(["ztreebox","parser","treebox"],function(){
					AJAX.init().success(function(c,m,d){
						$("#deptselect").ztreebox({
							edit:false,
							editable:true,
							searchable:true,
							data:d,
							ztreeopt:{ 
								async:{
									dataFilter:function(a,b,data,node){
										return data;
									}
								},
								check: {
									enable: true,
									chkStyle: "radio"
								}
							}
						});
						
					}).post(BASEPATH+'/base/authoriza/dept/getTreeall.htm');
					
				})
				var getValidateCode = function(){
					var thisclick = this;
					if(!$("#adduserdeptform").form("validate")){
						return;
					}else{
						AJAX.init().success(function(c,m,d){
							if(c==0){
								$.messager.show(''+ Obj.get("base.user.js.sysHint") +'',Obj.get("base.user.js.verCodeSent"));
								var countdown=15; 
								function settime(obj) { 
								    if (countdown == 0) { 
								        $('#userMobole').textbox('textbox').removeAttr('disabled'); 
								        obj.innerHTML=''+ Obj.get("base.user.js.getVerCode") +'',
								        obj.style.background="#1e8cfb";
								        $('#postcode').removeAttr('disabled');
								        countdown = 15; 
								        $('#postcode').bind('click',getValidateCode);
								        return;
								    } else { 
								        $('#userMobole').textbox('textbox').attr('disabled',true); 
								        obj.style.background="#ccc";
								        obj.innerHTML=""+Obj.get("base.user.js.resend")+"(" + countdown + ")"; 
								        $('#postcode').unbind('click');
								        countdown--; 
								    } 
								setTimeout(function() {
									settime(obj)},1000)
								}
								settime(thisclick);
							}
						}).error(function(c,m,d){
							if(!m&&m==""){
								$.messager.show(''+ Obj.get("base.user.js.sysHint") +'',Obj.get('base.user.js.verCodeSentFail'));
							}else{
								$.messager.show(''+ Obj.get("base.user.js.sysHint") +'',m);
							}
						}).post(BASEPATH+"/base/authoriza/user/addMakeSure.htm?phone="+$("#userMobole").textbox("getValue")+"&code="+$("#msgcode").textbox("getValue"));
					}
				}
				$('#postcode').bind("click",getValidateCode);
				$("#postcode").prev("span").css("float","left");
			},
			buttons: [{
				text:''+ Obj.get("base.user.js.save") +'',
				iconCls:'icon-ok',
				accessKey:{akey:18,mkey:83},
				handler:function(){
					if(!$("#adduserdeptform").form("validate")){
						return;
					}
					/*AJAX.init().success(function(c,m,d){
						if(m&&m==""){
							$.messager.show("系统提示",m);
							return;
						}
					}).post(BASEPATH+"/base/authoriza/user/addMakeSure.htm?phone="+$("#userMobole").textbox("getValue")+"&code="+$("#msgcode").textbox("getValue"));*/
					if(!$("#adduserdeptform2").form("validate")){
						return;
					}
					if($('#deptselect').siblings('span').find('input[type="hidden"]')[0].value==""){
						$.messager.show(''+ Obj.get("base.user.js.sysHint") +'',''+ Obj.get("base.user.js.selectDept") +'');
						return;
					}

					AJAX.init().success(function(code,msg,data){
						$.messager.show(''+ Obj.get("base.user.js.sysHint") +'',msg);
						dgutil.pager(1);
						$('#adduserdlg').dialog('close');
					}).error(function(c,m,d){
						$.messager.show(''+ Obj.get("base.user.js.sysHint") +'',m);
					}).post(BASEPATH+"/base/authoriza/user/updateUserDept.htm",{deptId:$('#deptselect').textbox("getValue"),code:$('#telephoneCode').textbox("getValue")});
				}
			},{
				text:''+ Obj.get("base.user.js.cancel") +'',
				addClass:'l-btn-red',iconCls:'icon-not',
				accessKey:{akey:18,mkey:67},
				handler:function(){
					$('#adduserdlg').dialog('close');
				}
			}]
		}).dialog("open");
	}
	var setExpireDate =  function(baseUrl,row){
		var editrow = row;
		using(["form"],function(){
			$("#setexpiredlg").dialog({
				iconCls: 'icon-save',
				title:''+ Obj.get("base.user.js.setExpireDate") +'',
				href:baseUrl,
				onLoad:function(){
					//查询用户设置的有效期
					AJAX.init().success(function(code,msg,data){
						if(data==null||data==undefined){
							data={userId:row.userId};
						}else{
							data.expirDate = (data.expirDate).substring(0,10)
						}
						$('#expireform').form('load',data);
					}).post(BASEPATH+'/base/authoriza/baseuser/ext/queryByUser.htm',{userId:row.userId});

				},
				buttons: [{
					text:''+ Obj.get("base.user.js.save") +'',
					iconCls:'icon-ok',
					accessKey:{akey:18,mkey:83},
					handler:function(){
						using(["form"],function(){
							var param = $("#expireform").serializeJson();
							if(param.expirDate!=""){//比较日期必须大于今天
								var now = getNowDate();
								if(param.expirDate<=now){
									$.messager.alert(Obj.get("base.user.js.sysHint") ,Obj.get("base.user.js.datemsg"));
									return ;
								}
							}
							AJAX.init().success(function(code,msg,data){
								dgutil.pager(1);
								$.messager.show(Obj.get("base.user.js.sysHint") ,msg)
								$('#setexpiredlg').dialog('close');
							}).error(function(code,msg,data){
								$.messager.show(Obj.get("base.user.js.sysHint") ,msg);
							}).post(BASEPATH+'/base/authoriza/baseuser/ext/save.htm',param);
						});
					}
				},{
					text:''+ Obj.get("base.user.js.cancel") +'',
					addClass:'l-btn-red',iconCls:'icon-not',
					accessKey:{akey:18,mkey:67},
					handler:function(){
						$('#setexpiredlg').dialog('close');
					}
				}]
			});
			$("#setexpiredlg").dialog("open");
		});
	}
	function getNowDate(){  
			var datetimeType = "";  
		    var date = new Date();  
		    datetimeType+= date.getFullYear();   //年  
		    datetimeType+= "-" + getMonth(date); //月   
		    datetimeType += "-" + getDay(date);   //日  
		    return datetimeType;
	} 
	//返回 01-12 的月份值   
	function getMonth(date){  
	    var month = "";  
	    month = date.getMonth() + 1; //getMonth()得到的月份是0-11  
	    if(month<10){  
	        month = "0" + month;  
	    }  
	    return month;  
	}  
	//返回01-30的日期  
	function getDay(date){  
	    var day = "";  
	    day = date.getDate();  
	    if(day<10){  
	        day = "0" + day;  
	    }  
	    return day;  
	}
	module.exports = {
			trans:function(){
				var param = function(obj_){
					Obj = obj_;
				//}
				var buttons ={ 
						title:{
							_class:"",
							text:''+ Obj.get("base.user.js.userList") +'',
						},
						btn:[
							 {
									iconCls: 'icon-search',
									url:'/view/base/user/userdeptadd',
									text:''+ Obj.get("base.user.js.disDept") +'',
									addClass:'l-btn-display',
									handler: addDeptToUser
							},
						     {
						    	 iconCls: 'icon-search',
						    	 url:'/base/authoriza/user/getByPaged.htm',
						    	 text:''+ Obj.get("base.user.js.query") +'',
						    	 addClass:'l-btn-display',
						    	 handler: function(){dgutil.pager(1);}
						     },
						     {
						    	 iconCls: 'icon-add',
						    	 addClass:'l-btn-display',
						    	 text:''+ Obj.get("base.user.js.add") +'',
						    	 url:'/view/base/user/useradd',
						    	 handler: addDialogInit
						     },
						     {
						    	 iconCls: 'icon-edit',
						    	 url:'/view/base/user/userupd',
						    	 text:''+ Obj.get("base.user.js.edit") +'',
						    	 addClass:'l-btn-display',
						    	 needRow:true,
						    	 handler: updDialogInit
						     },
						     {
						    	 iconCls: 'icon-remove',
						    	 url:'/base/authoriza/user/delete.htm',
						    	 text:''+ Obj.get("base.user.js.delete") +'',
						    	 addClass:'l-btn-display',
						    	 needRows:true,
						    	 isCheck:true,
						    	 handler: delInit
						     },
						     /*{
						    	 iconCls: 'icon-import',
						    	 url:'/base/authoriza/user/saveImport.htm',
						    	 text:"导入",
						    	 addClass:'l-btn-display',
						    	 handler: importDialogInit
						     },*/
						     {
						    	 iconCls: 'icon-assign',
						    	 url:'/base/authoriza/userrole/save.htm',
						    	 text:''+ Obj.get("base.user.js.roleAssign") +'',
						    	 addClass:'l-btn-display',
						    	 needRows:true,
						    	 handler: roleDialogInit
						     },
						     {
						    	 iconCls: 'icon-reset',
						    	 url:'/base/authoriza/user/updRestPsd.htm',
						    	 text:''+ Obj.get("base.user.js.rePwd") +'',
						    	 addClass:'l-btn-display',
						    	 needRow:true,
						    	 handler: resetpswd
						     },
						     {
						    	 iconCls: 'icon-reset',
						    	 url:'/view/base/user/setuserexpire',
						    	 text:''+ Obj.get("base.user.js.setExpireDate") +'',
						    	 addClass:'l-btn-display',
						    	 needRow:true,
						    	 handler: setExpireDate
						     }
						     ]};
				datagridconfig = {
						fitColumns:true,
						singleSelect:false,
						striped:true,
						autoRowHeight:false,
						fit: true,
						toolbar:buttons,
						columns:config().column,
						eid:"dg",
//						multiSort:true,
						remoteSort:false,
						ajaxCreater:function(){return AJAX.init().contentType('application/json');},
						argsFilter:function(args){
							args.depts = [];
							args.roles = [];
							$.each(args["depts.deptId"].split(","),function(i,item){
								if(item!="")
									args.depts.push({deptId:item});
							});
							delete args["depts.deptId"];
							$.each(args["roles.roleId"].split(","),function(i,item){
								if(item!="")
									args.roles.push({roleId:item});
							});
							delete args["roles.roleId"];
							return JSON.stringify(args);
						},
						url:BASEPATH+'/base/authoriza/user/getByPaged.htm',
						args:"searchform"
				};
				using(["datagrid","ztreebox","parser","textbox","messager","dialog","combobox","treebox"],function(){
					initpage();
					indexApp.exec("user",function(user){
						userModel = user;
						initUserType("searchUserType");
					});
				});
			}
			loadI18n('base/user1',param);	
		}
	}
});

var imgByUrl = function(url){
	var Obj = window.loadI18n('base/user1');
	if(url==undefined||url=="") return ;
	$("#playdlg").dialog({
		title:''+ Obj.get("base.user.js.image") +'',
		noheader:true,
		shadow:false,
		content:"<img style='height:100%' src='"+url+"'/>",
		width: 652,    
		height: 400,
		resizable:true
	});
	$(".window-mask").click(function(e){
		$("#playdlg").dialog("close");
	});
	$("#playdlg").dialog("restore");
	$("#playdlg").dialog("center");
	$("#playdlg").dialog("open");
}
